package app.sceledroid.network;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import app.sceledroid.entity.Course;
import app.sceledroid.entity.Deadline;
import app.sceledroid.entity.Forum;
import app.sceledroid.entity.Resource;

public class ForumGrabber extends AsyncTask<Document, Integer, ArrayList<Forum>> {

	private Context context;
	private HttpClient client;
	private Course course;
	
	public ForumGrabber(Course course, Context context, HttpClient client) {
		super();
		this.context = context;
		this.course = course;
		this.client = client;
	}
	
	
	@Override
	protected ArrayList<Forum> doInBackground(Document... params) {
		
		ArrayList<Forum> forums = new ArrayList<Forum>();
		course.setForums(forums);
		
		Document doc = params[0];
		Elements elements = doc.select("li.forum a");
		for (Element el : elements) {
			
				String href = el.attr("href");
				
				String rName = el.text();
				
				Forum forum = new Forum(rName, href);
				Log.v("FORUM", rName);
				forums.add(forum);
				
			
		}

		return course.getForums();
	}

}
